package com.lp.biz.operations.model.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.lp.biz.operations.model.entity.BizRecommendBanner;
import lombok.Data;

import java.time.LocalDateTime;

import static com.lp.common.constant.BannerConstant.TYPE_LINK;
import static com.lp.common.constant.CommonConstant.*;

/**
 * @program: backend
 * @description:
 * @author: Ke.Song
 * @since: 2024-07-15 22:58:09
 */
@Data
public class BannerList {

    private Integer id;

    private String imageUrl;

    /**
     * 是否是外部链接, 0: 不是, 1: 是
     */
    private Integer isExternal;

    /**
     * 外部链接地址
     */
    private String link;

    /**
     * 内部资源id
     */
    private Integer bizContentId;

    /**
     * 内部资源分类code
     */
    private String bizCategoryCode;

    private Integer isDisplay;

    @JsonFormat(timezone = TIMEZONE, pattern = DATE_MIN)
    private LocalDateTime startAt;

    @JsonFormat(timezone = TIMEZONE, pattern = DATE_MIN)
    private LocalDateTime endAt;

    @JsonFormat(timezone = TIMEZONE, pattern = DATE_TIME)
    private LocalDateTime createAt;

    private String type;

    public static BannerList builder(BizRecommendBanner banner) {
        BannerList bannerList = new BannerList();
        bannerList.setId(banner.getId());
        bannerList.setImageUrl(banner.getImageUrl());
        bannerList.setIsExternal(banner.getIsExternal());
        bannerList.setLink(banner.getLink());
        bannerList.setBizContentId(banner.getBizContentId());
        bannerList.setBizCategoryCode(banner.getBizCategoryCode());
        bannerList.setIsDisplay(banner.getIsDisplay());
        bannerList.setStartAt(banner.getStartAt());
        bannerList.setEndAt(banner.getEndAt());
        bannerList.setCreateAt(banner.getCreateAt());
        if (banner.getIsExternal().equals(SURE)) {
            bannerList.setType(TYPE_LINK);
        } else {
            bannerList.setType(banner.getBizCategoryCode());
        }
        return bannerList;
    }
}
